//
//  ReceiveMainCell.m
//  YKMediator_ReceiveModule
//
//  Created by linghit on 2021/8/17.
//

#import "ReceiveMainCell.h"
#import "ReceiveViewModel.h"
#import <Masonry/Masonry.h>
#import <YK_ExectionModel/YKExection.h>

@interface ReceiveMainCell ()
///
@property (nonatomic, strong, readwrite) UIView *bgView;
///
@property (nonatomic, strong, readwrite) UILabel *timeLabel;
///
@property (nonatomic, strong, readwrite) UILabel *titleName;
///
@property (nonatomic, strong, readwrite) UILabel *priceLabel;
///
@property (nonatomic, strong, readwrite) UILabel *ccNameLabel;
///
@property (nonatomic, strong, readwrite) UILabel *collLabel;
///
@property (nonatomic, strong, readwrite) UIButton *isCellButton;
@end

@implementation ReceiveMainCell

- (void)setupUI
{
    [super setupUI];
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    
    self.bgView = UIView.instance.yk_backgroundColor(YK_WHILE);
    self.bgView.layer.cornerRadius = 8;
    [self.bgView clipsToBounds];
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(lengthScale(15));
        make.top.mas_equalTo(lengthScale(5));
        make.right.mas_equalTo(-lengthScale(15));
        make.bottom.mas_equalTo(-lengthScale(5)).priorityHigh();
    }];
    
    self.timeLabel = UILabel.instance.yk_textColor(YK_TEXT_BLACK_333).yk_fontSize(12).yk_sizeToFit.yk_textAlignment(NSTextAlignmentCenter);
    [self.bgView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lengthScale(3));
        make.left.right.mas_equalTo(0);
    }];
    
    self.titleName = UILabel.instance.yk_textColor(YK_SUB_TITLE_GRAY_666).yk_fontSize(20).yk_sizeToFit;
    [self.bgView addSubview:self.titleName];
    [self.titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(lengthScale(10));
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(lengthScale(5));
    }];
    
    self.priceLabel = UILabel.instance.yk_textColor(YK_SUB_TITLE_GRAY_666).yk_fontSize(20).yk_sizeToFit;
    [self.bgView addSubview:self.priceLabel];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(lengthScale(10));
        make.top.mas_equalTo(self.titleName.mas_bottom).offset(lengthScale(5));
    }];
    
    self.ccNameLabel = UILabel.instance.yk_textColor(YK_SUB_TITLE_GRAY_666).yk_fontSize(20).yk_sizeToFit;
    [self.bgView addSubview:self.ccNameLabel];
    [self.ccNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(lengthScale(10));
        make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(lengthScale(5));
    }];
    
    self.collLabel = UILabel.instance.yk_textColor(YK_SUB_TITLE_GRAY_666).yk_fontSize(20).yk_sizeToFit;
    [self.bgView addSubview:self.collLabel];
    [self.collLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(lengthScale(10));
        make.top.mas_equalTo(self.ccNameLabel.mas_bottom).offset(lengthScale(5));
        make.bottom.mas_equalTo(self.bgView.mas_bottom).offset(-lengthScale(5));
    }];
    
    [self.bgView addSubview:self.isCellButton];
    [self.isCellButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-lengthScale(10));
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(lengthScale(2));
        make.size.mas_equalTo(CGSizeMake(lengthScale(45), lengthScale(20)));
    }];
}

- (void)configDataWithViewModel:(ReceiveViewModel *)viewModel indexPath:(NSIndexPath *)indexPath dataSource:(NSArray *)dataSource
{
    @weakify(self);
    [viewModel getDetail:indexPath detailBlock:^(NSString * _Nonnull Id, NSMutableAttributedString * _Nonnull detailName, NSMutableAttributedString * _Nonnull price, NSString * _Nonnull createTime, BOOL isCell, NSMutableAttributedString * _Nonnull cellName, NSMutableAttributedString * _Nonnull collcetionName,NSString * _Nonnull title) {
        @strongify(self);
        self.timeLabel.text = createTime;
        self.titleName.attributedText = detailName;
        self.priceLabel.attributedText = price;
        self.ccNameLabel.attributedText = cellName;
        self.collLabel.attributedText = collcetionName;
        
        self.isCellButton.selected = !isCell;
    }];
}

- (UIButton *)isCellButton
{
    if (!_isCellButton) {
        _isCellButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_isCellButton setBackgroundImage:YKHEXCOLOR(@"#00FFFF").image forState:UIControlStateNormal];
        [_isCellButton setBackgroundImage:YKHEXCOLOR(@"#FFB6C1").image forState:UIControlStateSelected];
        [_isCellButton setTitle:@"已收款" forState:UIControlStateNormal];
        [_isCellButton setTitle:@"未收款" forState:UIControlStateSelected];
        [_isCellButton setTitleColor:YK_SUB_TITLE_GRAY_999 forState:UIControlStateNormal];
        [_isCellButton setTitleColor:YK_SUB_TITLE_GRAY_999 forState:UIControlStateSelected];
        _isCellButton.titleLabel.font = [UIFont systemFontOfSize:10];
        _isCellButton.layer.cornerRadius = 10;
        _isCellButton.clipsToBounds = YES;
        _isCellButton.userInteractionEnabled = NO;
    }
    return _isCellButton;
}

@end
